package dataStructure.other;

/**
 * @author: vince_zww
 * @date: 2019/12/29 23:46
 * @desceription: ���ֲ���
 */
public class BinarySearch {

    public static int bsearch(int[] a,int n,int value){
        int low = 0;
        int high = n-1;
        while (low <= high){
            int mid = (low+high)/2;
            if(a[mid] == value){
                return mid;
            }else if(a[mid] < value){
                low = mid+1;
            }else {
                high = mid-1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] num = new int[]{1,2,3,4,5,6,7,8,9,10};

        System.out.println(bsearch(num,10,3));

        int a=7;
        int b=7;
        System.out.println(a--);
        System.out.println(a);
        System.out.println(--b);
        System.out.println(b);

    }

}
